% calculate_L2_Error.m
 ureal = reshape(u,NumGLP,Nx)';
%  data=load("final_data1001.txt");
%  ureal(:,1)=data(2,:);
%  data=load("final_data1002.txt");
%  ureal(:,2)=data(2,:);
%  data=load("final_data1003.txt");
%  ureal(:,3)=data(2,:);
%  data=load("final_data1004.txt");
%  ureal(:,4)=data(2,:);
%  data=load("final_data1005.txt");
%  ureal(:,5)=data(2,:);
uhG=zeros(Nx,NumGLP);
L2_Error=0;
for i = 1:Nx
    for d = 1:dimPk
        uhG(i,:) = uhG(i,:) + uh(i,d)*phiG(:,d)';
    end
end

uE = abs(uhG - ureal);

for i = 1:Nx
    for i1 = 1:NumGLP
        L2_Error = L2_Error + hx1*weight(i1)*uE(i,i1)^2;
    end
end
L2_Error = sqrt(L2_Error);